package logic

import (
	"context"
	"errors"
	"gorm.io/gorm"
	"regist-detail-sys/model/mysql"

	"regist-detail-sys/registrpc/internal/svc"
	"regist-detail-sys/registrpc/registrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRegisAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisAddLogic {
	return &RegisAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 挂号添加
func (l *RegisAddLogic) RegisAdd(in *registrpc.RegisAddRequest) (*registrpc.RegisAddResponse, error) {
	// todo: add your logic here and delete this line

	patient := mysql.Patient{
		Model:   gorm.Model{},
		Name:    in.Name,
		CarNum:  in.CarNum,
		Phone:   in.Phone,
		Address: in.Address,
	}

	err := patient.PatientAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("添加失败")
	}

	return &registrpc.RegisAddResponse{
		PatientId: int64(patient.ID),
	}, nil
}
